home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / graphics / bitvctr / readme.txt < prev   
Encoding:
Text File  |  1995-12-04  |  5.1 KB  |  157 lines

  1. Here's a simple class that fills a common need: A BitVector.
  2.  
  3. This software, and the included source code, is FREEWARE.
  4.  
  5. You may use it as you see fit in your own projects but you may 
  6. not re-sell the original or a derivative. If you redistribute 
  7. it you must include this disclaimer and all original copyright
  8. notices. 
  9.  
  10. No warranty is inferred or implied, as always seems to be the
  11. case with software these days. Use at your own risk. Keep away
  12. from small children. Don't exceed recommended dosage. I'm not
  13. liable, I'm not liable, I'm not liable.
  14.  
  15. It's not complete, or *extremely* well thought out I suppose,
  16. but it's a good starting point. You'll see some "TBD"s in the
  17. code which indicates that it's a work in progress.
  18.  
  19. There's not much code, and I haven't done any real docs on it
  20. yet, but it should be useful none-the-less and you can always
  21. e-mail questions to me.
  22.  
  23. I'd love to see people improve upon this work. Please keep me 
  24. posted if you do. If you should happen to change the behavior
  25. in a derivative version please change the class name so as not
  26. to cause problems with existing code.
  27.  
  28. Enjoy!
  29.  
  30. --Gregg Irwin [72450,676]
  31.  
  32. --------------------------------------------------------------
  33.  
  34. Q. What's a BitVector? 
  35.  
  36. A. It's just an array designed to store True/False values.
  37.  
  38. --------------------------------------------------------------
  39.  
  40. Q. Can't I just define an array of Boolean variables to do 
  41.    that?
  42.  
  43. A. Yes you can.
  44.  
  45. --------------------------------------------------------------
  46.  
  47. Q. Why would I want to use a BitVector instead of an
  48.    array of Boolean variables?
  49.  
  50. A. Size. Boolean variables are stored as 16-bit 
  51.    (2-byte) integers. If you have a small number of 
  52.    items to track then memory consumption may not be
  53.    a concern to you. If, however, you had 1,000,000
  54.    items to track then you might flinch a bit at using
  55.    2 meg of memory to do so. A BitVector uses only 1
  56.    bit per item, instead of 16 bits like a Boolean does.
  57.    To track 1,000,000 items you would only use 125K of
  58.    memory, rather than 2 meg.
  59.  
  60.    Under VB4/32 they may actually be stored as 32 bit
  61.    (i.e. long) integers if I recall correctly. The current
  62.    docs don't say so but it would make sense to make them
  63.    as fast as possible on 32 bit systems. Keeping things
  64.    aligned, etc.
  65.  
  66. --------------------------------------------------------------
  67.  
  68. Q. What's the downside?
  69.  
  70. A. Speed. Rather than referencing array variables directly
  71.    the BitVector has to do a bit of processing to identify
  72.    individual bits. Jim Mack has written routines in assembly
  73.    language (which are part of Microhelp Muscle) that should
  74.    be fast enough for *anybody*. Using a table to look up 
  75.    values could also speed things up a bit. There's a note
  76.    in the code about this idea.
  77.  
  78. --------------------------------------------------------------
  79.  
  80. Q. How do I use it?
  81.  
  82. A. It's easy.
  83.    
  84.    1. Dim a variable to hold the bit vector.
  85.  
  86.       Example: Dim BV As New BitVector
  87.  
  88.    2. Set the number of elements you want the BitVector to
  89.       hold using the NumElements property.
  90.  
  91.       Example: BV.NumElements = 25000
  92.  
  93.    3. Set, Get, Clear, Toggle, and Test bits by referencing 
  94.       their index.
  95.  
  96.       BV.SetBit 12345
  97.       BitVal = BV.GetBit 12345
  98.       BV.ClearBit 12345
  99.       BV.ToggleBit 12345
  100.       On = BV.IsBitSet 12345
  101.  
  102. --------------------------------------------------------------
  103.  
  104. Q. What's the difference between GetBit and IsBitSet?
  105.  
  106. A. GetBit returns the actual value of the bit (1 or 0) while
  107.    IsBitSet returns a boolean value of True or False.
  108.  
  109. --------------------------------------------------------------
  110.  
  111. Q. What if I want to set, or clear, all of the bits at once?
  112.  
  113. A. Simple. Use the SetAll or ClearAll methods.
  114.  
  115. --------------------------------------------------------------
  116.  
  117. Q. Why a class module?
  118.  
  119. A. Why not? It has a defined interface. It provides 
  120.    encapsulation. It allows you to create multiple instances
  121.    easily. It can be used as an OLE server. It can raise
  122.    errors effectively. 'nuff said?
  123.  
  124. --------------------------------------------------------------
  125.  
  126. Q. What if I forget how many elements are in a BitVector?
  127.  
  128. A. Use the NumElements method to find out.
  129.  
  130.    Example: ElCount = BV.NumElements
  131.  
  132. --------------------------------------------------------------
  133.  
  134. Q. What if I "grow" a BitVector (i.e. increase NumElements)?
  135.  
  136. A. It remembers the current bit states so you'll need to 
  137.    clear them manually if that's what you want. New bits will
  138.    be "off" initially.
  139.  
  140. --------------------------------------------------------------
  141.  
  142. Q. What if I have suggestions, requests, or improvements?
  143.  
  144. A. Send them to me and I'll get back to you as quickly as I 
  145.    can. Hopefully we can make it a community effort and build
  146.    up a good library of tools that we can all draw upon.
  147.  
  148. --------------------------------------------------------------
  149.  
  150. Q. What if it has a bug in it that costs me millions of 
  151.    dollars?
  152.  
  153. A. Re-read the disclaimer and let me know about the bug 
  154.    please.<g>
  155.  
  156. --------------------------------------------------------------
  157.